/*
** main.c for my_mastermind in /home/deubel_j//colle
** 
** Made by james deubelbeiss
** Login   <deubel_j@epitech.net>
** 
** Started on  Mon Apr 18 19:16:50 2011 james deubelbeiss
** Last update Mon Apr 18 22:44:44 2011 james deubelbeiss
*/

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "my_mastermind.h"

t_args	*init_struct()
{
  t_args	*ar;

  ar = xmalloc(sizeof(*ar));
  ar->code = xmalloc(sizeof(char) * 5);
  ar->pions = xmalloc(sizeof(char) * 9);
  ar->pions[0] = '0';
  ar->pions[1] = '1';
  ar->pions[2] = '2';
  ar->pions[3] = '3';
  ar->pions[4] = '4';
  ar->pions[5] = '5';
  ar->pions[6] = '6';
  ar->pions[7] = '7';
  ar->tentatives = 10;
  ar->slots = 4;
  return (ar);
}

t_args	*parse_opts(int ac, char **av)
{
  int	i;
  t_args	*ar;

  i = 0;
  ar = init_struct();
  while (av[i] != NULL)
    {
      if (strcmp(av[i], "-s") == 0)
	do_s(ar, av, i);
      else if (strcmp(av[i], "-c") == 0)
	do_c(ar, av, i);
      else if (strcmp(av[i], "-p") == 0)
	do_p(ar, av, i);
      else if (strcmp(av[i], "-t") == 0 && av[i + 1] != NULL)
	ar->tentatives = my_atoui(av[i + 1]);
      i++;
    }
  if (ar->c != 42)
    do_no_code(ar);
  return (ar);
}
